/* BEGIN_COMMON_COPYRIGHT_HEADER
 * (c)LGPL2+
 *
 * Copyright: 2011 Razor team
 *            2014 LXQt team
 * Authors:
 *   Alexander Sokoloff <sokoloff.a@gmail.com>
 *   Maciej Płaza <plaza.maciej@gmail.com>
 *   Kuzma Shapran <kuzma.shapran@gmail.com>
 *
 * Copyright: 2019 Tianjin KYLIN Information Technology Co., Ltd. *
 *
 * This program or library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * END_COMMON_COPYRIGHT_HEADER */

#ifndef UKUITASKPOPUP_H
#define UKUITASKPOPUP_H

#include <QHash>
#include <QFrame>
#include <QLayout>
#include <QTimer>
#include <QEvent>
#include <QDBusInterface>
#include <QDBusReply>

#include "ukuitaskbutton.h"
#include "ukuitaskgroup.h"
#include "ukuitaskwidget.h"
#include "ukuitaskbar.h"

#define PREVIEW_WINDOW_WIDTH  420
#define PREVIEW_WINDOW_HEIGHT 264
#define PREVIEW_TITLE_HEIGHT  46
#define PREVIEW_SPACEING      8
#define LIST_WINDOW_WIDTH     246
#define LIST_WINDOW_HEIGHT    46

#define PANEL_CONFIG_PATH  "/usr/share/ukui/ukui-panel/panel-commission.ini"

class UKUIGroupPopup: public QFrame
{
    Q_OBJECT

public:
    UKUIGroupPopup(UKUITaskGroup *group);
    ~UKUIGroupPopup();

    void hide(bool fast = false);
    void show();

    // Layout
    void removeWidget(QWidget *button) { layout()->removeWidget(button); }
    void pubcloseWindowDelay() { closeWindowDelay(); }


    void addWindow(const WindowId& id,UKUITaskBar *bar);
    void onWindowRemoved(const WindowId& id);
    void onWindowChanged(const WindowId& id);

    void caculateTaskWidget();
    void caculateQmlWidget();
    void showPreviewMode();
    void showAllWindowByList();//when number of window is more than 30,need show all window of app by a list
    void showAllWindowByThumbnail();//when number of window is no more than 30,need show all window of app by a thumbnail
    void removeWidget();
    void removeSrollWidget();
    void caculatePopupWidgetPos();
    QRect calculatePopupWindowPos(QPoint const & absolutePos, QSize const & windowSize) const;
    void setRegionBlur();

protected:
    void dragEnterEvent(QDragEnterEvent * event);
    void dragLeaveEvent(QDragLeaveEvent *event);
    void leaveEvent(QEvent * event);
    void enterEvent(QEvent * event);
    void paintEvent(QPaintEvent * event);
    void mousePressEvent(QMouseEvent *event);

    void closeTimerSlot();
    void sendCloseSigToKWin();

private:
    UKUITaskGroup *m_group;
    QTimer m_closeTimer;
    bool m_rightclick;

    bool isKeepShow = false;

    UKUISdkTaskWidgetHash m_widgetHash;
    int m_allWidgetWidth = 0;
    int m_allWidgetHeight = 0;
    bool m_isShowByList = false;
    QWidget *m_widget;
    QScrollArea *m_scrollArea = NULL;

    bool m_useOpenGL;
    QDBusInterface *m_interface;
    bool m_isXrender;
    QGSettings *m_changeTheme;

private slots:
    void killTimerDelay();
    void closeWindowDelay();

    void setKeepShow(bool flag);
    void setKeepLeave(bool flag);

};

#endif // UKUITASKPOPUP_H
